<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属仓库" prop="wareId">
        <el-select v-model="queryParams.wareId" placeholder="请选择" filterable clearable>
          <el-option
            v-for="i in wares"
            :key="i.id"
            :label="i.name"
            :value="i.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="商品编号" prop="skuId">
        <el-input
          v-model="queryParams.skuId"
          placeholder="请输入商品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称" prop="skuName">
        <el-input
          v-model="queryParams.skuName"
          placeholder="请输入商品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <el-table-column label="编号" align="center" prop="id"/>
      <el-table-column label="商品编号" align="center" prop="skuId"/>
      <el-table-column label="商品名称" align="center" prop="skuName"/>
      <el-table-column label="所属仓库" align="center" prop="wareName"/>
      <el-table-column label="库存数" align="center" prop="stock"/>
      <el-table-column label="锁定库存" align="center" prop="stockLocked"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>

export default {
  name: 'index',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        wareId: undefined,
        skuId: undefined,
        skuName: undefined
      },
      uri: '/ware/wareSku',
      wares: []
    }
  },
  created() {
    this.getList()
    this.getWares()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      this.$api.get(this.uri, this.queryParams).then(({ data }) => {
        this.list = data.records
        this.total = data.total
        this.loading = false
      })
    },
    getWares() {
      this.$api.get('/ware/wareInfo/all').then(({ data }) => {
        this.wares = data
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>

<style scoped>
</style>
